package com.base.system.controller;

import java.util.Arrays;

import com.base.system.service.ITSysRoleService;
import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.base.common.annotation.RepeatSubmit;
import com.base.common.annotation.Log;
import com.base.common.core.controller.BaseController;
import com.base.common.core.domain.PageQuery;
import com.base.common.core.domain.R;
import com.base.common.core.validate.AddGroup;
import com.base.common.core.validate.EditGroup;
import com.base.common.enums.BusinessType;
import com.base.system.domain.vo.TSysRoleVo;
import com.base.system.domain.bo.TSysRoleBo;
import com.base.common.core.page.TableDataInfo;

/**
 * 角色
 *
 * @author base
 * @date 2023-10-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/sysRole")
public class TSysRoleController extends BaseController {

    private final ITSysRoleService iTSysRoleService;

    /**
     * 查询角色列表
     */
// @SaCheckPermission("system:sysRole:list")
    @GetMapping("/list")
    public R<TableDataInfo<TSysRoleVo>> list(TSysRoleBo bo, PageQuery pageQuery) {
        return R.ok(iTSysRoleService.queryPageList(bo, pageQuery));
    }

    /**
     * 获取角色详细信息
     *
     * @param roleId 主键
     */
    //    @SaCheckPermission("system:sysRole:query")
    @GetMapping("/{roleId}")
    public R<TSysRoleVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String roleId) {
        return R.ok(iTSysRoleService.queryById(roleId));
    }

    /**
     * 新增角色
     */
//     @SaCheckPermission("system:sysRole:add")
    @Log(title = "角色", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TSysRoleBo bo) {
        return toAjax(iTSysRoleService.insertByBo(bo));
    }

    /**
     * 修改角色
     */
    //   @SaCheckPermission("system:sysRole:edit")
    @Log(title = "角色", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TSysRoleBo bo) {
        return toAjax(iTSysRoleService.updateByBo(bo));
    }

    /**
     * 删除角色
     *
     * @param roleIds 主键串
     */
    //  @SaCheckPermission("system:sysRole:remove")
    @Log(title = "角色", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roleIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] roleIds) {
        return toAjax(iTSysRoleService.deleteWithValidByIds(Arrays.asList(roleIds), true));
    }
}
